package demo6;

import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-09-04
 * Time: 21:32
 */

/*class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int compareTo(Student o) {
        if(this.age > o.age) {
            return 1;
        }else if(this.age < o.age) {
            return -1;
        }else {
            return 0 ;
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                '}';
    }
}*/

class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age='" + age + '\'' +
                '}';
    }

}

//比较器
class Agecompare implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
class NameComparator implements Comparator<Student> {
    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

public class Test {

    public static void main(String[] args) {
        Student student1 = new Student("zhangsan",3);
        Student student2 = new Student("lisi",15);

        Agecompare agecompare = new Agecompare();
        System.out.println(agecompare.compare(student1, student2));

        System.out.println("=======================================");

        NameComparator nameComparator = new NameComparator();
        System.out.println(nameComparator.compare(student1, student2));

        //System.out.println(student1.compareTo(student2));
        // 对象不可比较，需要进行比较，解决这个问题。要根据什么比？姓名？年龄？

    }

    public static void main1(String[] args) {
        //两个整数比较大小
        int a = 10;
        int b = 20;

        System.out.println( a>b );
    }
}
